package dm.ast.model.gen.factory;

import java.util.ArrayList;
import java.util.List;

//GROUJP BY 的复杂度模叛设置
public class GroupModelFactory extends BaseModelFactory {

    static int MAX_ELEMENTS = 512;

    //根据宽度、深度,返回 GroupBy 子句模型
    public static ComplexityModel groupModels(int wid_t, int dep_t) {
        List<ComplexityModel> models = new ArrayList<ComplexityModel>();
        if (dep_t != 1) {//目前不考虑 groupby 子句可句可能为子查询的情况
            throw new AssertionError(" GroupByDepth ");
        }
        //常规分配
        models.add(modelNormal(wid_t, dep_t));
        return BaseModelFactory.getRanComplexityModel(models);
    }

    //一般情况下将group by子句分割为每个宽度为1的分组项

    private static ComplexityModel modelNormal(int wid_t, int dep_t) {
        /**
         * //根据宽度是多少，生成
         * public ComplexityModel(int count){
         *         this.count = count;
         *         init();
         *     }
         */
        ComplexityModel model1 = new ComplexityModel(wid_t);
        for (int i = 0; i < model1.count; i++) {  //这里的model1.count就是上面的宽度wid_t
            model1.comps[i].wid_t = 1;
            model1.comps[i].dep_t = 1;
        }
        return model1;
    }
}